using Common.Commands;
using Common.Commands.TaskLogCommands;
using Common.Commands.TemplateCommands;
using Core.Domain.Model;
using Core.Infrastructure.CustomExceptions;
using Sanelib.DataOperation;
using Sanelib.Dto;

namespace Core.Processors.TaskLogProcessors
{
    public class DeleteTaskLogProcessor : ICommandProcessor<DeleteTaskLog>
    {
        private readonly IRepository<TaskLog> _taskLogRepository;

        public DeleteTaskLogProcessor(IRepository<TaskLog> taskLogRepository)
        {
            _taskLogRepository = taskLogRepository;
        }

        public dynamic Process(DeleteTaskLog command)
        {
            var response = new WebApiResultResponse();

            var taskLog = _taskLogRepository.GetById(command.Id);

            if (taskLog == null)
                throw new DomainProcessException("Task Log not available");

            _taskLogRepository.Delete(taskLog.Id);
            response.IsSuccess = true;

            return response;
        }
    }
}
